/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.service.ro.impl;

import java.util.List;

import com.us.usws.cache.BaseDictCache;
import com.us.usws.cache.UserCache;
import com.us.usws.common.SiteConstants;
import com.us.usws.dao.ClzDAO;
import com.us.usws.dao.SchoolDAO;
import com.us.usws.model.domain.system.Clz;
import com.us.usws.model.domain.system.School;
import com.us.usws.service.ro.ClzROService;
import com.us.usws.support.ext.CacheManager;
import com.us.usws.support.uitls.DataPageUtil;

/**
 * Service RO impl class
 * @author robot
 */
public class ClzROServiceImpl implements ClzROService {

	/**
	 * DAO instance
	 */
	private ClzDAO dao = new ClzDAO();
	
	private SchoolDAO schoolDao = new SchoolDAO();

	/**
	 * Get Count.
	 */
	@Override
	public int getTotalCount() {
		return dao.getTotalCount();
	}

	/**
	 * Get all list.
	 */
	@Override
	public List<Clz> getAllClzs() {
		return dao.getAllClzs();
	}
	
	public void loadSchoolsByPage(DataPageUtil<Clz> dataPageUtil) {
		dao.loadSchoolsByPage(dataPageUtil);
		List<Clz> clzs = dataPageUtil.getResult();
		if(clzs != null && clzs.size() > 0) {
			BaseDictCache dc = CacheManager.getDictCache();
			UserCache uc = CacheManager.getUserCache();
			for(Clz clz:clzs) {
				clz.setGradeName(dc.getDictNameByCode(SiteConstants.DICT_DOMAIN_SCHOOL_GRADE, clz.getClzGradeCode()));
				clz.setCreateUserName(uc.getUserName(clz.getCreateByUid()));
				
				School sc = schoolDao.getSchool(clz.getSchoolUid());
				
				if(sc != null) {
					clz.setSchoolCode(sc.getCode());
					clz.setSchoolName(sc.getName());
				}
			}
		}
	}

	/**
	 * Get all list by pagination.
	 */
	@Override
	public List<Clz> getClzs(int start, int end) {
		return dao.getClzs(start, end);
	}

	/**
	 * Get Clz by primary key.
	 */
	@Override
	public Clz getClz(String uid) {
		Clz c = dao.getClz(uid);
		return c;
	}

}